package com.force.jianghuling.application;

import android.app.Application;
import android.content.Context;

import com.avos.avoscloud.AVOSCloud;
import com.force.jianghuling.BuildConfig;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpHeaders;
import com.lzy.okgo.model.HttpParams;

import org.xutils.x;

/**
 * Created by liyanchi on 2016/11/25.
 */
public class JiangHuApplication extends Application {

    private static Context context;


    @Override
    public void onCreate() {
        super.onCreate();

        context = this;
        initOkhttp();//初始化Okhttp
        x.Ext.init(this);
        x.Ext.setDebug(BuildConfig.DEBUG);//是否输出debug日志,开启会影响性能
        AVOSCloud.initialize(context, "i5bb1lWlF4KzN0wc0X5WMmfP-gzGzoHsz", "XC2MRatuIkSRTjKnu7kG722u");

        //        //测试LeanCould
        //        AVObject testObject = new AVObject("TestObject");
        //        testObject.put("foo", "bar");
        //        testObject.saveInBackground();

    }
    /**
     * 初始化okhttp
     */
    private void initOkhttp() {

        HttpHeaders headers = new HttpHeaders();
//        添加公共表头
        /**
         *  -H "X-LC-Id: i5bb1lWlF4KzN0wc0X5WMmfP-gzGzoHsz" \
         -H "X-LC-Key: XC2MRatuIkSRTjKnu7kG722u" \
         -H "Content-Type: application/json" \
         */
        headers.put("X-LC-Id", "i5bb1lWlF4KzN0wc0X5WMmfP-gzGzoHsz");
        headers.put("X-LC-Key", "XC2MRatuIkSRTjKnu7kG722u");
        headers.put("Content-Type", "application/json");
        HttpParams params = new HttpParams();
//        params.put("commonParamsKey1", "commonParamsValue1");     //所有的 params 都 支持 中文
//        params.put("commonParamsKey2", "这里支持中文参数");
        //必须调用初始化
        OkGo.init(this);
        //以下都不是必须的，根据需要自行选择
        OkGo.getInstance()//
                .debug("OkHttpUtils")                                              //是否打开调试
                .setConnectTimeout(OkGo.DEFAULT_MILLISECONDS)               //全局的连接超时时间
                .setReadTimeOut(OkGo.DEFAULT_MILLISECONDS)                  //全局的读取超时时间
                .setWriteTimeOut(OkGo.DEFAULT_MILLISECONDS)                 //全局的写入超时时间
                //.setCookieStore(new MemoryCookieStore())                           //cookie使用内存缓存（app退出后，cookie消失）
                //.setCookieStore(new PersistentCookieStore())                       //cookie持久化存储，如果cookie不过期，则一直有效
                .addCommonHeaders(headers)                                         //设置全局公共头
                .addCommonParams(params);                                          //设置全局公共参数

    }
}
